import 'package:get/get.dart';
import '../../../services/userServices.dart';
import '../../../models/user_model.dart';

class UserController extends GetxController {
  //TODO: Implement UserController

  RxBool isLogin = false.obs;
  // RxList userList = [].obs;
  var userInfo = UserModel().obs;

  @override
  void onInit() {
    super.onInit();
    getUserInfo();
  }

  @override
  void onClose() {
    super.onClose();
  }

  //获取用户信息，以及登录状态
  getUserInfo() async {
    var tempLoginState = await UserServices.getUserLoginState();
    isLogin.value = tempLoginState;
    var tempList = await UserServices.getUserInfo();
    if (tempList != []) {
      userInfo.value = UserModel.fromJson(tempList[0]);
    }
    update();
  }
}
